<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<input type="button" value="发送ajax请求" onclick="send()">
<input type="button" value="发送ajax请求" onclick="send()">
<script>
	function send() {
	  
	}
	var ss = ajax("get","ajax.php","username=zhangsan",function (responseData) {
	  console.log(responseData);
	});
	//编写一个方法用来发送请求，接收数据
	function ajax(type,url,data,success) {
		var responseData;
		//底层是封装的XMLHttpRequest
	    var xhr = new XMLHttpRequest();
	    xhr.open(type,url+"?"+data);
	    xhr.send(null);
	    //接收数据
	    xhr.onreadystatechange = function () {
	        if(xhr.status ===200 && xhr.readyState===4){
		        responseData = xhr.responseText;
		        success(responseData)
	        }
	    }
	}
</script>
</body>
</html>